/***************************************************************************
 创建者: 华磊
 开始时间: 2020.8.14
 copyright: (C) 深圳市华友高科有限公司
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2020.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef MAPVIEW_H
#define MAPVIEW_H

#include <QDialog>
#include <QGraphicsScene>
#include <qtimer.h>
#include "mapdelegate.h"
#include <QStandardItem>
#include "bezier.h"


class MapScene;
class MapLogic;
class MapGraphicsView;
class BallJoyStick;
class MapDelegeta;
class MapEditToolBox;
class ReflectEditDialog;
class MainWindowFleet;

namespace Ui {
class MapView;
}

#define D_RECORD_MAP_SELECTI_POINT 2
/**
 * @brief The MapView class
 */
class MapView : public QDialog
{
    Q_OBJECT

public:
    explicit MapView(MapDelegate *mapDelegateIn,QWidget *parent = 0);
    ~MapView();

public:

    /**
     * @brief reloadMap 重新加载地图
     * @param mapPath
     * @return
     */
    int reloadMap();
    /**
     * @brief setVehiclePosition　设置地图中车的位置，用于显示
     * @param x　unit is m
     * @param y　unit is m
     * @param a　unit is degree
     * @return
     */
    int setVehiclePosition(double x,double y,double a);

    /**
     * @brief setVmarkPosition          设置VMark位置
     * @param x                         VMark位置坐标X
     * @param y                         VMark位置坐标Y
     * @param a                         VMark度数
     * @param isDetectedIn              是否探测
     * @return
     */
    int setVmarkPosition(double x,double y,double a,bool isDetectedIn);

    /**
     * @brief getCurrentSeletPosision 获取当前用户在地图选择的点
     * @return
     */
    VehiclePosition& getCurrentSeletPosision();

//        void updateMapView();


public slots:

    /**
     * @brief showMapViewDialog     显示地图界面
     */
    void showMapViewDialog();

    /**
     * @brief showPointsInMap_Slot  在地图上显示点位
     */
    void showPointsInMap_Slot();

    void disableVehicleJog_slot();

private slots:
    void getMapFile_slot();
    void timeroutslot();

    void setShowLandPoint_Slot(bool isShow);
    void setChangeOriginalLaserFilter_slot(int filterIndex);
    void setShowReflectDialog_Slot(bool isShow);
    void displayAllReflectMarksInMap_slot(bool isDisplay);

    void setShowNormalPositionCircule_slot(bool isShow);
    void setShowReflectPositionCircule_slot(bool isShow);
    void setShowReflectCar_slot(bool isShow);
    void setShowCommonCar_slot(bool isShow);

    void on_pushButton_zoomIn_clicked();

    void on_pushButton_zoomOut_clicked();


    void on_checkBox_clicked(bool checked);


    void on_checkBox_3_clicked(bool checked);

    void on_pushButton_setPosition_clicked();

    void on_pushButton_moveToPosition_clicked();


    void on_pushButton_mapHide_clicked();

//    void on_pushButton_loadMap_2_clicked();

//    void on_pushButton_browseFile_clicked();

//    void on_pushButton_createMapStart_clicked();

//    void on_pushButton_createMapStop_clicked();

    void on_pushButton_setMapSolver_clicked();

    void on_pushButton_setOdomSolver_clicked();

    void on_pushButton_setLocationSolver_clicked();

    void on_pushButton_getVehiclePosition_clicked();

//    void on_pushButton_setVehiclePosition_clicked();

    void on_pushButton_setTrajectoryGlobalPlanSolver_clicked();

    void on_pushButton_setTrajectoryLocalPlanSolver_clicked();

//    void on_pushButton_moveToPosition_2_clicked();

    void on_pushButton_changeVelocity_clicked();

    void on_pushButton_start_clicked();

    void on_pushButton_cease_clicked();

    void on_pushButton_stop_clicked();

    void on_recodMapDPoint_Btn_clicked();

    void on_pushButton_front_trans_pressed();

    void on_pushButton_back_trans_pressed();

    void on_pushButton_left_trans_pressed();

    void on_pushButton_right_trans_pressed();

    void on_pushButton_left_rotation_pressed();

    void on_pushButton_right_rotation_pressed();

    void jogFrontLeftPressed();
    void jogFrontRightPressed();
    void jogBackLeftPressed();
    void jogBackRightPressed();

    void on_pushButton_front_trans_released();

    void on_pushButton_back_trans_released();

    void on_pushButton_left_trans_released();

    void on_pushButton_right_trans_released();

    void on_pushButton_left_rotation_released();

    void on_pushButton_right_rotation_released();

    void on_pushButton_reset_vehicle_short_odom_clicked();

    void on_pushButton_update_map_list_clicked();

    void on_pushButton_loadMap_clicked();

    void on_pushButton_createMapStart_2_clicked();

    void on_pushButton_endMap_and_save_clicked();

    void on_pushButton_setLaserFilterType_clicked();

    void on_pushButton_saveVmarkFIle_clicked();

    void on_pushButton_updateVmarkInfoByFile_clicked();

    void on_pushButton_getVmakrsInfo_clicked();

    void on_verticalSlider_speed_jog_sliderMoved(int position);

    void on_verticalSlider_speed_jog_Edit_textChanged(const QString &arg1);

    void on_verticalSlider_speed_jog_valueChanged(int value);

//    void on_checkBox_ultrasonicCheckEnable_clicked(bool checked);

//    void on_checkBox_pointCloudCheckEnable_clicked(bool checked);

    void on_pushButton_loadMap_3_clicked();    
    void on_checkBox_isShowLaserData_clicked(bool checked);

    void on_pushButton_toogleCheckBarrior_clicked();

    void on_pushButton_bezier_clicked();

    void on_pushButton_bezier_addUserPoint1_clicked();

    void on_pushButton_bezier_addUserPoint2_clicked();

    void on_pushButton_fitIn_clicked();

    void on_pushButton_download_all_map_clicked();

    void on_pushButton_delectSelectedMap_clicked();

    void on_pushButton_resetAndServoOn_clicked();

//    void on_pushButton_clrMsgServoOn_clicked();

    void on_checkBox_fleetMainWindow_clicked(bool checked);

    void on_pushButton_refreshMapProperty_clicked();

    void on_pushButton_bezier_byControlPoints_clicked();
    void loginControllerSucess_slot();

signals:
    void loginControllerSucess_signal();
    void controllerLoginSignal(QVector<int> controllerIpAddress,QVector<int> hmiIpAddress,QString port,QString passwardString,int selectedAccount);

    void reordMapPointSignal(int recordType);
    void msgBoxSignal(int type,QString title,QString text);
    //发布一个agv位置信息
    void sig_pub_agv_position(int id,QString name,double x,double y,double theta,
                              QStringList occus,int floor);
protected:
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);

private:
    int removeMapFile(std::string fileName);
    int getMapImageFile();
    int zoomKeyBoard_press(int tmpKey, bool isAutoRepeat);
    int jogKeyBoard_press(int tmpKey, bool isAutoRepeat);
    int jogKeyBoard_release(char tmpKey, bool isAutoRepeat);
    int jogKeyBoard_stopMonitor();
    int showTargetPoint(VehiclePosition posIn);
    int showCurrentPath(VehiclePosition startPosition, std::vector<VehiclePosition> targetPosition, E_NAV_COMMAND currentPathType,
                        double &currentPathParameter1, double &currentPathParameter2);
    int updatePositionFeedback(PositionInfo_hmi positionReturn);
    int showBasicStatus(VehicleBasicInfo &basicInfoIn);
    int showPositionInfo();
    int checkMap(QString runningMap);
//    int drawCar(double x_pix, double y_pix, double a_degree);// pix, pix, degree
//    int drawLaserPoint(std::vector<struct PointCloudData_3D> &pointCloudOut,double x,double y,double a);
//    int initialCar();
//    int initialLaserPoint();
    void test();
    void updateMatrix();
    void carJogControl();
    int checkJogCondition();
    void initialShowStyle();
    void initialFleetWindow();
    int jog_button_logic();
    int showVmarkDetectInfo();
    int showQrcodeDetectInfo();
    int displayAmclDebugInfo();


private:
    Ui::MapView *ui;
    MapScene *scene;
    QTimer *timer;
//    VehicleItem *vehicleItem;
//    BaseMapImage *baseMap;
    BallJoyStick *ballJoyStick;
    MapDelegate *mapDelegate;
    MapEditToolBox *mapEditToolBox;
    ReflectEditDialog* reflectEditDialog;

    /**
     * @brief currenPosition        载入地图点时,地图界面选中的当前点位数据
     */
    VehiclePosition currenPosition;

    qreal scaleRatio;
    qreal rotateAngel;//degree
    qreal xOffset;//M
    qreal yOffset;//M

    MapLogic *mapLogic;
    MapGraphicsView *mapGraphicsView;

    double car_positionX_P;//PIX
    double car_positionY_P;//PIX
    double car_positionA_P;//degree

    double vmark_positionX_P;//PIX
    double vmark_positionY_P;//PIX
    double vmark_positionA_P;//degree
    bool vmark_isDetected;

    double car_positionX_M;//M
    double car_positionY_M;//M
    double car_positionA_M;//degree

    double car_speed;
    double battery_left;
    QString current_task;
    int car_mode;
    int car_status;

    QString currentShowMapName;

    int jogFlag;
    QStandardItemModel* model_vmarksInfoInfo;
    QStandardItemModel* model_vmarksDebugInfo;
    QStandardItemModel* model_qrcodeDebugInfo;
    QStandardItemModel* model_amclDebugInfo;
    bool isCheckBarrier;
    int jogKeyBoardReleaseFlag;//0:无动作　１：按下去　２：松开
    int jogKeyPressedCount;

#ifdef D_USE_FLEET_WINDOW
   MainWindowFleet *mainWindowFleet;
#endif

};

#endif // MAPVIEW_H
